<?php
	/* ******************************************************** */
	/* Arcans Project (2010)                                    */
	/* Jeu 3D en temps réel par navigateur, conception et       */
	/* Développement dans la notice                             */
	/* Jeu sous licence GNU GPL v3 (voir NOTICE et COPYING)     */
	/* ******************************************************** */

	//*****************************
	//class de création des boutons
	//*****************************
	class ButtonClass {
		//propriétés :
		private $name;
		private $href;
		//méthodes :
		function __construct($info) { $this->name = $info["name"]; $this->href = $info["href"]; }
		public function affichage() {
			if (preg_match("/^[?]+/",$this->href)) return '<a href="'.$this->href.'">'.$this->name.'</a>';
			else return '<a href="#" onclick="javascript:'.$this->href.'">'.$this->name.'</a>';
		}
		public function affichageXML($doc) {
			if (preg_match("/^[?]+/",$this->href)) {
				$lien = $doc->createElement("a");
				$lien->setAttribute('href',$this->href);
				$lien->appendChild($doc->createTextNode($this->name));
				return $lien;
			}
			else {
				$lien = $doc->createElement("a");
				$lien->setAttribute('href','#');
				$lien->setAttribute('onclick','javascript:'.$this->href);
				$lien->appendChild($doc->createTextNode($this->name));
				return $lien;
			}
		}
	}
	//**************************
	//classe de création du menu
	//**************************
	class MenuClass {
		//propriétés :
		private $buttonlist;
		//méthodes :
		function __construct($listMenu) {
			$i = 0;
			foreach ($listMenu as $elt) {
				$info["name"] = $elt->getAttribute("name");
				$info["href"] = $elt->getAttribute("href");
				$this->buttonlist[$i] = new ButtonClass($info);
				$i++;
			}
		}
		function affichage() {
			echo '<td id="logo2">&nbsp;</td><td id="menutd"><table>';
			$i = 1;
			foreach ($this->buttonlist as $element) {
				if ($i%2 == 1) echo '<tr><td class="buttontd" id="td'.$i.'">'.$element->affichage().'</td>';
				else echo '<td class="buttontdno"></td><td class="buttontd" id="td'.$i.'">'.$element->affichage().'</td></tr>';
				$i++;
			}
			if ($i%2 == 1) echo '</tr>';
			echo '</table></td>';
		}
		function affichageXML($doc, $table_entete) {
			$td_logo2 = $doc->createElement("td");
			$td_logo2->setAttribute('id','logo2');
			$td_logo2->appendChild($doc->createTextNode(' '));
			$table_entete->appendChild($td_logo2);

			$td_menutd = $doc->createElement("td");
			$td_menutd->setAttribute('id','menutd');
			$table_entete->appendChild($td_menutd);

			$table_menu = $doc->createElement("table");
			$td_menutd->appendChild($table_menu);

			//echo '<td id="logo2">&nbsp;</td><td id="menutd"><table>';
			$i = 1;
			foreach ($this->buttonlist as $element) {
				if ($i%2 == 1) {
					$tr = $doc->createElement("tr");
					$table_menu->appendChild($tr);

					$td = $doc->createElement("td");
					$td->setAttribute('class','buttontd');
					$td->setAttribute('id','td'.$i);
					$lien = $element->affichageXML($doc);
					$td->appendChild($lien);
					$tr->appendChild($td);
					//echo '<tr><td class="buttontd" id="td'.$i.'">'.$element->affichage().'</td>';
				}
				else {
					if (!isset($tr)) {
						// Au cas où....
						$tr = $doc->createElement("tr");
						$table_menu->appendChild($tr);
					}
					$td = $doc->createElement("td");
					$td->setAttribute('class','buttontdno');
					$tr->appendChild($td);

					$td = $doc->createElement("td");
					$td->setAttribute('class','buttontd');
					$td->setAttribute('id','td'.$i);
					$lien = $element->affichageXML($doc);
					$td->appendChild($lien);
					$tr->appendChild($td);
					//echo '<td class="buttontdno"></td><td class="buttontd" id="td'.$i.'">'.$element->affichage().'</td></tr>';
				}
				$i++;
			}
			//if ($i%2 == 1) {
				//echo '</tr>';
			//}
			//echo '</table></td>';
		}
	}
?>